package edu.nf.ch01.converter;

import edu.nf.ch01.entity.Teacher;
import edu.nf.ch01.entity.User;
import edu.nf.ch01.vo.UserVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author wangl
 * @date 2025/10/23
 */
@Mapper
public interface UserConverter {

    /**
     * 获取当前类的转换器（代理对象）
     */
    UserConverter INSTANCE = Mappers.getMapper(UserConverter.class);

    /**
     * 将User对象转换为UserVO
     * @param user
     * @return
     */
    @Mappings({
         @Mapping(source = "username", target = "userName"),
         @Mapping(source = "age", target = "userAge"),
         @Mapping(source = "card.cardNum", target = "cardNum")
    })
    UserVO toUserVO(User user);

    /**
     * 多参数源拷贝
     * 注意：多参数源时source需要指定参数名称
     * @param user
     * @param teacher
     * @return
     */
    @Mappings({
            @Mapping(source = "user.username", target = "userName"),
            @Mapping(source = "user.age", target = "userAge"),
            @Mapping(source = "user.card.cardNum", target = "cardNum"),
            @Mapping(source = "teacher.name", target = "teacherName")
    })
    UserVO toUserVO(User user, Teacher teacher);

}